//
//  YCTeachPlanDetailViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/24.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  教学详情

#import "YCTeachPlanDetailViewController.h"
#import "YCTeachDetailCell.h"

// for test
#import "YCCoachHomeForStudentViewController.h"
#import "YCNavigationViewController.h"

@interface YCTeachPlanDetailViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,YCTeachDetailCollectionViewCellDelegate>

/** collectionView  */
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;

/** 头部view  */
@property (nonatomic, strong) UIView *headView;
/** 日  */
@property (nonatomic, weak) UILabel *dayLabel;
/** 月  */
@property (nonatomic, weak) UILabel *monthLabel;
/** 教学计划图标  */
@property (nonatomic, weak) UIImageView *planIconView;
/** 教学计划文本  */
@property (nonatomic, weak) UILabel *planContentLabel;
/** 应到学员图标  */
@property (nonatomic, weak) UIImageView *studentIconView;
/** 应到学员文本  */
@property (nonatomic, weak) UILabel *studentCountLabel;
@end

@implementation YCTeachPlanDetailViewController

- (UIView *)headView
{
    if (!_headView) {
        _headView = [[UIView alloc] init];
        _headView.backgroundColor = [UIColor whiteColor];
        
        
        UIImageView *planIconView = [[UIImageView alloc] init];
        planIconView.image = [UIImage imageNamed:@"教学计划"];
        [_headView addSubview:planIconView];
        _planIconView = planIconView;
        
        
        UILabel *planContentLabel = [[UILabel alloc]init];
        planContentLabel.font = [UIFont boldSystemFontOfSize:14];
        planContentLabel.text = @"教学计划 半坡起步";
        planContentLabel.textColor = [UIColor yc_colorWithUInt:0x333333];
        [_headView addSubview:planContentLabel];
        _planContentLabel = planContentLabel;
        
        
        UIImageView *studentIconView = [[UIImageView alloc] init];
        studentIconView.image = [UIImage imageNamed:@"应到学员"];
        [_headView addSubview:studentIconView];
        _studentIconView = studentIconView;
        
        UILabel *studentCountLabel = [[UILabel alloc]init];
        studentCountLabel.font = [UIFont boldSystemFontOfSize:14];
        studentCountLabel.text = @"5人";
        studentCountLabel.textColor = [UIColor yc_colorWithUInt:0x333333];
        [_headView addSubview:studentCountLabel];
        _studentCountLabel = studentCountLabel;
        
        
        [studentIconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_headView).offset(30);
            make.bottom.equalTo(_headView).offset(-20);
            make.height.width.equalTo(@20);
        }];
        
        [studentCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(studentIconView);
            make.left.equalTo(studentIconView.mas_right).offset(10);
        }];
        
        [planIconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.width.height.equalTo(studentIconView);
            make.bottom.equalTo(studentIconView.mas_top).offset(-20);
        }];
        
        [planContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(planIconView);
            make.left.equalTo(planIconView.mas_right).offset(10);
        }];
        
    }
    return _headView;
}

- (void)navViewMake
{
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭"
                                                                 style:UIBarButtonItemStylePlain
                                                                target:self.navigationController
                                                                action:@selector(popViewControllerAnimated:)];
    [leftItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor yc_colorWithUInt:0x333333]} forState:UIControlStateNormal];
    
    self.navigationItem.leftBarButtonItem = leftItem;
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
    UILabel *dayLabel = [[UILabel alloc]init];
    dayLabel.font = [UIFont boldSystemFontOfSize:28];
    dayLabel.textAlignment = NSTextAlignmentRight;
    dayLabel.text = @"15";
    dayLabel.textColor = [UIColor yc_colorWithUInt:0x333333];
    [self.view addSubview:dayLabel];
    _dayLabel = dayLabel;
    
    UILabel *monthLabel = [[UILabel alloc]init];
    monthLabel.font = [UIFont boldSystemFontOfSize:12];
    monthLabel.textAlignment = NSTextAlignmentRight;
    monthLabel.text = @"4月";
    monthLabel.textColor = [UIColor yc_colorWithUInt:0x333333];
    [self.view addSubview:monthLabel];
    _monthLabel = monthLabel;
    
    [dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(-0);
        make.right.equalTo(self.view).offset(-20);
    }];
    
    [monthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(dayLabel);
        make.top.equalTo(dayLabel.mas_bottom).offset(0);
    }];
    
}


- (UICollectionView *)collectionView
{
    
    if (!_collectionView) {
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        layout.minimumInteritemSpacing = 2;
        layout.minimumLineSpacing = 20;
        layout.itemSize = CGSizeMake((kScreenWidth-80)/3.0,160);
        layout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
        _layout = layout;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth,0) collectionViewLayout:layout];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];//
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        [_collectionView registerClass:[YCTeachDetailCell class] forCellWithReuseIdentifier:@"teachDetailCell"];
    }
    return  _collectionView;
}

#pragma mark - 生命周期

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.headView];
    [self.view addSubview:self.collectionView];
    [self navViewMake];
    
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.equalTo(@100);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headView.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - UICollectionView datasource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSInteger count = 6;
    
    return count;
}

#pragma mark - UICollectionView delegate

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    YCTeachDetailCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"teachDetailCell" forIndexPath:indexPath];
    cell.delegate = self;
    [cell.iconImage yc_setWebImageWithURLString:@"http://b.hiphotos.baidu.com/image/h%3D200/sign=8de92df279cb0a469a228c395b63f63e/8c1001e93901213f391481d456e736d12f2e9597.jpg" holderSize:self.layout.itemSize];
    cell.nameLabel.text = @"Ailsa";
    [cell.upDownButton setTitle:@"下车" forState:UIControlStateNormal];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    YCLog(@"点击了cell中的collectionView的cell的第:%zd个item",indexPath.item);
    YCCoachHomeForStudentViewController *vc = [[YCCoachHomeForStudentViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark - YCTeachDetailCollectionViewCellDelegate

- (void)teachDetailCell:(YCTeachDetailCell *)teachDetailCell didClickUpdownBtn:(UIButton *)upDownButton
{
    
    YCLog(@"按钮点击了:%@",[upDownButton titleForState:UIControlStateNormal]);
    
}

#pragma mark - 点击事件






@end
